package com.smalls.newvideotwo.util;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.smalls.newvideotwo.NewDTVApp;
import com.smalls.newvideotwo.R;
import com.smalls.newvideotwo.base.ContentView;

/**
 * Created by wang on 2017/3/12.
 */
public class UIHelper {

    public static int getContentViewRes(Object o) {
        try {
            Class<?> clazz = o.getClass();
            ContentView contentView = clazz.getAnnotation(ContentView.class);
            if (contentView != null) {
                return contentView.value();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static Dialog createLoadingDialog(Context context, String msg) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.loading_dialog, null);
        final Dialog dialog = new Dialog(context, R.style.style_exit_dialog);
        dialog.setContentView(v);
        ((TextView) v.findViewById(R.id.dialog_context)).setText(msg);
        return dialog;
    }


    public static void toastServerConnectErr() {
        Toast.makeText(NewDTVApp.getApp(), "服务器连接失败", Toast.LENGTH_SHORT).show();
    }

    public static void toastServerResponseErr(String msg) {
        Toast.makeText(NewDTVApp.getApp(), msg, Toast.LENGTH_SHORT).show();
    }
}
